Sharing Formats for Document Pages
You need to clone a format object when a user wants to share a format, created using the Custom Page Setup dialog box, with an additional page in the same document. For example, a user may have a four-page document that consists of one page in landscape orientation and three pages that use the default format. A user may decide that page 3 of this document should also use landscape orientation.When the user clicks on page 3 and chooses the Format button in the Custom Page Setup dialog box, you need to clone the format object currently used for page 2 in this document.
Figure 3-15 shows a four-page document in which the second and third pages use the same format. Pages 1 and 4 use the default format.
Figure 3-15 A four-page document in which pages 2 and 3 use the same format object
Listing 3-10 shows how to clone a format object when it becomes shared. You should note that the
GXCloneFormat
function increments the owner count of this format object by 1. In this example, the format object is shared by two pages in a single document, so its owner count is also 2.Listing 3-10 Cloning a format object for two pages in a document
OSErr MyApplyPageFormat(MyDocumentPtr myDocument, gxFormat aNewFormat) { OSErr err = noErr; gxFormat pageFormat; /* If the specified format object is not the same as the default format, clone it so it can be shared by different pages. If it is the default format, set the reference to nil, which specifies using the default format. */ if ((aNewFormat != nil) && (aNewFormat != GXGetJobFormat(myDocument->documentJob, 1))) { pageFormat = GXCloneFormat(aNewFormat); err = GXGetJobError(myDocument->documentJob); } else pageFormat = nil; /* If there are no errors, dispose of the old format object and store the new one. Reformat the page, if necessary. */ if (err == noErr) { if (myDocument->pageFormat[myDocument->curPage -1] != nil) GXDisposeFormat (myDocument->pageFormat[myDocument->curPage-1]); myDocument->pageFormat[myDocument->curPage -1] = pageFormat; /* Place code here if your application needs to adjust the document based on the new format object. */ ... } return err; }
Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help